package com.ffz.calcitesql.demo;

import com.ffz.calcitesql.enums.ETableType;
import com.ffz.calcitesql.sql.ParseResult;
import com.ffz.calcitesql.sql.SqlParserImpl;
import com.ffz.calcitesql.sql.parse.SqlParserFactory;
import com.ffz.calcitesql.sql.utils.SqlFormatUtil;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.util.HashMap;

public class testParseSQLDemo {
    private static SqlParserFactory parserFactory = SqlParserFactory.getInstance();
    public static void main(String[] args) {

        SqlParserImpl sqlParser = parserFactory.getSqlParser(ETableType.HIVE);
        ParseResult parseResult;
        String sql="SELECT sum(x.dd) as xx ,2 from db.a x where id = xx and c = 'zz' ";
        try {
            parseResult = sqlParser.parseSql(sql, "test", new HashMap<>());
        } catch (final Exception e) {
            System.out.println("get sql error，sql");
            parseResult = new ParseResult();
            parseResult.setFailedMsg(ExceptionUtils.getStackTrace(e));
            parseResult.setStandardSql(SqlFormatUtil.getStandardSql(sql));
        }
        System.out.println(parseResult.toString());
    }
}
